package main

import (
	"context"
	"fmt"
	"go.etcd.io/etcd/api/v3/mvccpb"
	"go.etcd.io/etcd/client/v3"
	"time"
)

func main() {
	var (
		config     clientv3.Config
		client     *clientv3.Client
		kv         clientv3.KV
		err        error
		deleteResp *clientv3.DeleteResponse
		kvpair     *mvccpb.KeyValue
	)
	config = clientv3.Config{
		Endpoints:   []string{"47.106.109.134:2379"},
		DialTimeout: 5 * time.Second,
	}
	if client, err = clientv3.New(config); err != nil {
		fmt.Println(err)
		return
	}
	// get目录下所有值
	kv = clientv3.NewKV(client)
	if deleteResp, err = kv.Delete(context.TODO(), "cron/jobs/job1", clientv3.WithPrevKV()); err != nil {
		fmt.Println(err)
		return
	}
	if len(deleteResp.PrevKvs) != 0 {
		for _, kvpair = range deleteResp.PrevKvs {
			fmt.Println("deleted: ", string(kvpair.Key), string(kvpair.Value))
		}
	}
}
